package data;

import java.sql.Connection;


import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import dataTransferObject.Raza;


public class JDBCRazaDAO implements IRazaDAO {
	
	
	
	public JDBCRazaDAO(){
	}
	
	
	@Override
	public Raza selectRaza(Connection conn,int idRaza) {
		PreparedStatement stmt = null;
		 ResultSet result = null;
		 Raza raza = null;
		 String sql = "SELECT * FROM raza WHERE (ID_RAZA=?);";

		        try {
		            stmt = conn.prepareStatement(sql);
		            stmt.setInt(1, idRaza);
		            result = stmt.executeQuery();

		            while (result.next()) {
		            	 
		            	raza=new Raza();
		            	raza.setIdRaza(idRaza);
		            	raza.setDescripcion(result.getString("DESCRIPCION"));
		            	raza.setNombre(result.getString("NOMBRE"));
		            	raza.setTamano(result.getString("TAMANO"));
		            	 
		            }
		            
		           
		        } catch (SQLException e) {
		            System.out.println("selectRaza Message: " + e.getMessage());
		            System.out.println("selectRaza SQLState: " + e.getSQLState());
		            System.out.println("selectRaza ErrorCode: " + e.getErrorCode());
		        } finally {
		            try {
		                if (result != null) {
		                    result.close();
		                }
		                if (stmt != null) {
		                    stmt.close();
		                }
		            } catch (SQLException e) {
		            }
		        }

		        return raza;	
	}

}
